﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
namespace BUS
{
    public class PhieuThuePhongBUS
    {
        public const int vuotQuaSoKhachQuyDinh = 0;
        public const int thatBai = 1;
        public const int thanhCong = 2;
        public static int LapPhieuThuePhong(PhieuThuePhongDTO phieuThuePhong)
        {
            List<QuyDinhDTO> DSQD = QuyDinhBUS.LayDSQuyDinh(-1, "Số khách tối đa");
            if (phieuThuePhong.SoLuongKhach > DSQD[0].MoTa)
                return vuotQuaSoKhachQuyDinh;
            if (!PhieuThuePhongDAO.LapPhieuThuePhong(phieuThuePhong))
                return thatBai;
            return thanhCong;
        }
        public static int SuaPhieuThuePhong(PhieuThuePhongDTO phieuThuePhong)
        {
            if (phieuThuePhong.SoLuongKhach > 3)
                return vuotQuaSoKhachQuyDinh;
            if (!PhieuThuePhongDAO.SuaPhieuThuePhong(phieuThuePhong))
                return thatBai;
            return thanhCong;
        }
        public static List<PhieuThuePhongDTO> LayDSPhieuThuePhong(int maPhieuThuePhong = -1, int maKhachHang = -1, int thang = -1, int nam = -1, int maPhong = -1,int maPhongDeXoa = -1)
        {
            return PhieuThuePhongDAO.LayDSPhieuThuePhong(maPhieuThuePhong, maKhachHang, thang, nam, maPhong,maPhongDeXoa);
        }
        public static bool XoaPhieuThuePhong(int _maPhieuThuePhong)
        {
            if (PhieuThuePhongDAO.XoaPhieuThuePhong(_maPhieuThuePhong))
            {
               //Xoa cac chi tiet thue phong lien quan
                List<ChiTietPhong_SanPhamDTO> dsCT = ChiTietPhong_SanPhamBUS.LayDSChiTietPhong_SanPham(-1, _maPhieuThuePhong);
                if (dsCT != null && dsCT.Count > 0)
                {
                    foreach (var item in dsCT)
                        if (!ChiTietPhong_SanPhamBUS.XoaChiTietPhong_SanPham(item.MaCT))
                            return false;
                }

                return true;
            }
            return false;
        }
    }
}
